layui.use('form', function(){
  const form = layui.form;
  //监听提交
  form.on('submit(formDemo)', function(data){
    // ajax
    $.ajax({
      type: 'POST',
      url: 'https://api.yizhanketang.cn/api/v1/todos',
      data: data.field,
      success(res) {
        console.log(res)
      },
      error(e) {
        layer.msg('不能缺少content字段');
      }
    })
    // console.log(data.field)
    return false;
  });
});

$(function() {

  $.ajax({
    method: 'GET',
    url: 'https://api.yizhanketang.cn/api/v1/todos',
    success(res) {
      const { data } = res
      data.forEach(item => {
        const {completed, content: title, objectId} = item
        $(`<div class="item">
          <input type="checkbox" ${ completed ? 'checked' : '' }>
          <a href="todo.html?id=${objectId}"> ${ title }</a>
        </div>`).appendTo('.list')

        /*
        $(`<div class="item">
          <input type="checkbox" ${ item.completed && 'checked' }>
          <a href="javascript:void(0)"> ${item.content}</a>
        </div>`).appendTo('.list')*/

      })
    }
  })

})



